package drg_group.wuhan_2022.MDC;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import drg_group.wuhan_2022.Base;
import drg_group.wuhan_2022.MedicalRecord;
import drg_group.wuhan_2022.ADRG.*;

public class MDCR{
    public static String group(MedicalRecord record){
        String[] mdc_zd={"R58.x00x005","C83.000","C83.703","D36.700x023","C76.100","Z85.804","C92.100x014","Z08.000","C83.304","D19.900x001","Z51.802","Z51.800x921","C83.300x009","Z85.000x008","C85.715","C94.400x001","C79.800x813","D15.200x001","C84.000","D36.700x016","Z85.002","Z85.600x001","C83.503","R58.x00x007","C76.304","C76.801","C79.900","D47.404","C90.000x023","C85.100x010","C85.709","C93.300x001","Z51.800x097","C85.900x026","C92.100x004","C92.000x017","C92.900x011","D15.701","Z85.800x002","C79.800x811","C90.000x009","C91.000x013","C92.000x014","C90.000x037","D36.700x029","C77.301","C92.007","C92.103","C91.400x004","C83.003","Q85.900x016","Z85.408","C46.800","D44.701","C76.200x002","Z51.807","C76.501","Z85.205","C77.501","C85.900x041","D36.700x024","C90.000x030","C83.002","C90.000x024","C88.200x011","C96.603","Z51.003","C88.700x012","D46.900","C88.700x013","C83.800","D48.300x001","D15.200","C78.601","Z85.204","C84.500x012","C91.100","Z85.800x005","C79.900x001","D46.700x002","C85.707","C92.002","D17.701","C92.703","D46.900x002","C79.800x804","C91.900","C82.200","C84.402","C90.300x002","C75.400","C96.602","D47.100x017","D47.200x005+G63.1*","C91.101","C92.700x012","C80.900","C48.201","D47.900x001","C91.004","C94.000x001","C95.900x003+M36.1*","D36.706","Z85.100","Z51.800x095","C92.401","C91.000","C85.900x027","C85.900x002","C94.000x011","D36.705","D44.703","C90.000x028","C96.700","C90.200x009","C77.206","C85.900x037","C88.900x001","C95.900x013+M36.1*","D48.100x008","C76.502","Z51.000x013","C85.900x017","C83.802","D19.000","C92.004","C77.500","D36.717","D47.900","Z85.807","Z85.809","C79.800x817","C92.502","D48.900","C88.701","D36.712","C92.005","C92.900","Z51.800x951","Z86.003","C83.101","C88.000x012","D36.700x013","C95.000","C86.600","C84.901","C92.700","C92.000x003","C79.800x809","C82.400","C84.000x003","C85.900x008","D15.200x002","Z85.005","D36.710","C92.000x015","D44.700x002","C93.100x011","C84.404","D36.718","C46.900","Z86.001","C85.900x013","C94.201","Z51.500x003","C88.200x012","C78.201","Z51.500x001","C95.900x015","C79.807","Z85.808","C96.604","Z51.500x002","D47.700","C90.000x021","Z51.801","D48.714","D47.401","C90.300","C48.800","C91.500x011","D48.709","C95.000x116","C79.800x834","D15.900","C92.102","C85.900x030","C83.800x006","C88.700x003","Z85.806","C90.000x035","C83.900","D17.702","C90.000x039","Z51.001","C85.700","C90.301","C92.300x011","Z85.000x001","C95.700x011","C96.400x002","Z51.002","C83.801","D47.100x007","C81.900","C94.400","D48.400x003","Q85.802","C76.402","D46.600","C79.826","D47.403","D48.700x019","C85.700x004","C97.x01","Z51.000x003","C94.004","C92.100x002","C93.100x013","C96.401","C91.500","C84.100","C88.300","C95.000x002","Z51.800x094","C48.100x006","C77.300x003","C80.905","C91.700","C96.400x001","C92.100x012","C45.100","C79.829","Z85.203","C92.100x011","Z51.100x004","C84.401","C92.000x006","C79.800x837","C94.600","Z51.200x008","C91.000x006","C92.006","C94.700x004","D46.700x003","C85.900x031","C96.501","C78.604","D48.722","C91.800","C85.900x004","C93.100x012","C91.600","Z85.500x002","C91.000x017","D48.401","C48.104","C46.100","C90.000x038","C76.500","Z51.102","C77.302","C93.101","C95.006","Z51.806","C77.900","C84.900","C95.700x003","C95.100x011","C88.201","C92.200x011","D36.711","Z51.805","D48.716","C95.700x002","C92.000x016","D36.709","C95.000x101","C96.004","C45.700x002","C85.900","C83.300x007","C92.200","C83.307","C92.100x017","D46.901","C76.400","Z08.800x003","C85.900x028","D47.100x004","C83.300","C85.900x001","C92.001","C92.101","C83.100","D47.703","D19.100","C76.306","Z85.500","Z09.200","Z85.800x006","C46.300","D47.004","Z85.700x001","C82.703","C96.704","C90.000x041","C95.000x016","C85.704","D48.713","C83.302","D48.723","Z85.406","C83.300x008","C91.100x011","C83.102","C92.500x011","D46.900x006","D36.700x011","C76.401","C96.000","C96.900","C95.700x001","Z51.800x927","D20.103","D20.101","C86.000","D45.x00","C84.502","C84.405","D48.718","Z51.101","C88.700x002","C90.000x008+M90.6*","C85.900x003","Z85.801","C96.400x004","C90.000x022","C91.100x012","C96.202","Q85.900x015","C85.100x021","C92.700x013","D47.200x004+G63.1*","Z51.104","C48.100","C90.000","C84.500x004","C96.200x005","C77.202","D18.011","Z51.800x092","C94.700x014","C76.302","C76.503","D46.700x008","Z85.404","C83.700","Z92.600","C83.305","C88.203","C82.300","C85.900x024","Z51.800x096","C85.900x022","C92.701","D09.900","C93.002","C85.900x005","C77.503","C79.827","C90.000x029","C88.400","C95.000x018","C90.200x013","C90.000x012","Z51.800x981","Z85.701","C76.300x001","C77.205","D48.400x002","C49.901","C90.000x005","C88.401","D18.105","C96.402","C90.000x036","C96.201","C96.400","D36.704","Q85.801","Z51.000x012","Z51.800x953","Z51.800x983","C85.901","Z51.809","C79.809","D15.700","C78.600x004","C97.x00","C77.400x001","Z51.800x924","D47.003","Z85.101","D18.106","D17.400","C76.702","C81.700","D48.700x004","C90.000x033","C88.000","C92.100","C82.704","C90.200","C90.300x001","Z09.100","C85.700x016","C96.200x013","C92.300x013","C85.705","C77.303","C93.701","C91.000x016","C91.000x015","C79.811","C90.100","D36.707","D48.715","C85.100","C83.300x006","C45.706","Z85.400x008","C76.305","C84.500x016","C85.900x009","C95.002","C85.900x014","D48.720","C46.700","C83.306","D47.100x009","C85.900x019","C46.900x004","C48.103","D36.715","Z51.000x008","C85.900x040","C95.900x005","C91.003","C81.702","D18.012","Z08.200","C83.800x008","C84.406","D36.700x009","C92.200x001","C95.004","C88.000x002","C80.902","C96.400x003","C78.602","C77.401","C91.000x007","C92.100x016","C93.300","C48.000x002","C76.300","D48.700x016","C91.002","Z51.810","C84.700","Z51.800x922","C79.800x838","D48.700x001","C90.300x003","C91.007","C80.004+G73.1*","C92.000x018","Z85.810","D47.700x005","Z08.800x002","C80.904","C85.900x020","C92.100x001","C79.800x816","D47.702","C81.400","D48.707","C85.701","C95.000x115","D46.700x006","C77.502","D47.900x002","D47.000","D36.700x038","Z85.402","D36.713","C95.000x117","Z85.004","C85.900x011","Z85.800x011","Z85.403","C84.400","C95.000x017","C85.900x010","D20.000x002","C88.403","C92.300x003","D36.700x036","C88.200","C76.300x009","D48.700x015","D48.719","Z85.802","C91.000x014","C93.103","D09.700x002","C92.700x006","D48.708","C82.903","C90.100x002","C92.901","C84.600","C86.500","C90.303","C93.700","C93.001","C46.900x002","D36.700x035","C92.100x019","C84.400x001","Q85.806","C83.303","Z51.804","C90.100x011","Z85.008","C94.202","C83.702","C85.200","C94.200x011","D47.001","C91.300","Z85.003","D48.700x013","C96.500","C95.000x118","D48.700x005","Q85.909","C45.100x005","C92.600","C96.601","D47.100","Z08.700","Z85.502","C83.501","D38.300x002","C93.901","Z54.001","Z85.501","C83.803","C91.400","C83.004","C95.003","C85.900x025","C91.008","C88.302","C92.800","C91.102","C79.800x862","C91.901","C95.100","C46.900x003","C81.300","C92.000","Z85.001","C77.900x001","Z85.805","C85.100x017","C95.100x012","C95.901","D36.700x032","D48.717","Z85.009","D47.200","D36.700x012","D38.300x003","Z85.300x001","D36.700x021","Z85.803","D36.700x014","C79.800x818","C90.000x040","C76.200","C90.000x026","C90.000x004","C92.201","C85.900x036","D46.700x001","D38.301","C84.403","C86.300","C90.000x034","D36.700x008","C88.000x011","C94.702","C76.701","C90.000x032","C96.800","Z08.800x001","C92.300x001","C94.700","C90.000x011","C81.100","C84.500","C78.605","C92.000x011","C80.901","C81.701","C85.900x023","C92.402","C96.200","D48.724","Z86.002","Z85.407","Z51.103","C85.900x042","D09.700x001","C77.800","C90.000x027","D46.700","C48.000","C93.900","D47.700x007","C84.000x002","D48.710","C90.000x025","D48.301","D48.700x010","D36.700x019","C81.200","C85.900x006","C90.200x008","D47.402","C92.000x012","C45.900","C85.900x034","C93.000x011","C82.701","C88.402","D36.708","C95.000x102","C77.300x001","Z51.808","D47.002","C94.001","D47.100x008","Z08.800x004","Z85.007","C84.601","C83.001","C91.000x009","C80.903","C81.000","Z85.800x003","D20.000","D47.200x003","C92.601","C85.900x016","C85.900x015","C95.900","D38.300x001","C82.702","C91.401","D20.100","Z51.811","C81.703","C48.105","C83.502","C92.008","C90.000x014","C85.900x043","C86.601","Z85.400x003","C96.600","Z85.401","C91.001","C90.300x004","C88.301","C84.800","C88.900","C86.200","Z51.800x952","C96.200x006","C82.900","D44.601","D36.714","C91.704","C91.400x013","C95.000x003","Z85.006","D47.100x019","C82.100","C96.502","D47.101","C96.002","C92.100x018","C83.301","C86.603","C45.700","Z85.900","D47.701","C77.200","C93.104","C86.100","C95.000x015","C96.801","C48.200","C83.800x009","C81.900x005","C92.300","Z85.503","C90.002","C96.705","C93.102","D47.100x018","D47.400","D46.900x004","C92.900x001","C92.400x011","C93.000x016","Z85.409","C82.700","C85.900x029","C92.009","C91.006","Z51.800x925","C91.000x012","C92.706","C94.300x011","C76.700x002","C83.500","D17.500","C91.701","D48.700x023","C86.400","C94.703","C94.200","C93.003","Z08.100","C83.504","C86.602","C90.000x031","Z85.201","D47.300","C88.202","C76.101","C92.000x013","D36.700x030","C82.901","C92.501","D36.716","D47.700x006","C82.000","D48.725","C96.403","C45.103","C92.003","C94.300","C88.700","C77.300","C83.505","D46.700x007","D17.400x001","C84.407","C90.001","C76.100x003","C79.821","C93.100","C95.005","C77.107","C85.900x012","C82.600","C92.403","C95.900x012","D36.700x018","C82.500","C90.302","Z08.900","D47.500"};
        String[] dept_list={};
        if (!(true && Base.contains(mdc_zd,record.zdList[0]))){
            return "";
        }
        
        Base.groupMessages.putMessage(record.Index,"符合MDCR入组条件，匹配规则：主诊断匹配");
        String result;

        result=RA1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RA2.group(record);
        if (result.length()>0){
            return result;
        }

        result=RA3.group(record);
        if (result.length()>0){
            return result;
        }

        result=RA4.group(record);
        if (result.length()>0){
            return result;
        }

        result=RB1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RC1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RD1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RE1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RF1.group(record);
        if (result.length()>0){
            return result;
        }

        if (false && record.ssList!=null && record.ssList.length>0  && Base.intersect(Base.SS_VALID,record.ssList)){
            Base.groupMessages.putMessage(record.Index,"符合RQY入组条件，存在有效手术操作："+String.join(",",Base.Intersect(record.ssList,Base.SS_VALID)));
            return "RQY";
        }

        result=RR1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RS1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RS2.group(record);
        if (result.length()>0){
            return result;
        }

        result=RT1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RT2.group(record);
        if (result.length()>0){
            return result;
        }

        result=RU1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RU2.group(record);
        if (result.length()>0){
            return result;
        }

        result=RV1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RW1.group(record);
        if (result.length()>0){
            return result;
        }

        result=RW2.group(record);
        if (result.length()>0){
            return result;
        }

        Base.groupMessages.putMessage(record.Index,"不符合MDCR的ADRG入组条件");
        return "";
    }
}

